<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="会员充值促销" prop="hyUserGoldPromotionId">
									<el-input v-model="form.hyUserGoldPromotionId" placeholder="请输入会员充值促销" clearable></el-input>
								</el-form-item>
								<el-form-item label="区域限制" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入区域限制" clearable></el-input>
								</el-form-item>
								<el-form-item label="开始时间" prop="startTime">
									<el-input v-model="form.startTime" placeholder="请输入开始时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="结束时间" prop="endTime">
									<el-input v-model="form.endTime" placeholder="请输入结束时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="币种 CurrencyGlobal参数配置" prop="currency">
									<el-input v-model="form.currency" placeholder="请输入币种 CurrencyGlobal参数配置" clearable></el-input>
								</el-form-item>
								<el-form-item label="面值金额" prop="pvalue">
									<el-input v-model="form.pvalue" placeholder="请输入面值金额" clearable></el-input>
								</el-form-item>
								<el-form-item label="销售金额" prop="pprice">
									<el-input v-model="form.pprice" placeholder="请输入销售金额" clearable></el-input>
								</el-form-item>
								<el-form-item label="标题" prop="ptitle">
									<el-input v-model="form.ptitle" placeholder="请输入标题" clearable></el-input>
								</el-form-item>
								<el-form-item label="标题图片" prop="ptitleImg">
									<el-input v-model="form.ptitleImg" placeholder="请输入标题图片" clearable></el-input>
								</el-form-item>
								<el-form-item label="简述" prop="shortDesc">
									<el-input v-model="form.shortDesc" placeholder="请输入简述" clearable></el-input>
								</el-form-item>
								<el-form-item label="描述" prop="fullDesc">
									<el-input v-model="form.fullDesc" placeholder="请输入描述" clearable></el-input>
								</el-form-item>
								<el-form-item label="0失效 1激活 2过期" prop="state">
									<el-input v-model="form.state" placeholder="请输入0失效 1激活 2过期" clearable></el-input>
								</el-form-item>
								<el-form-item label="排序 降序" prop="seq">
									<el-input v-model="form.seq" placeholder="请输入排序 降序" clearable></el-input>
								</el-form-item>
								<el-form-item label="总数量 -100不限数量" prop="sl">
									<el-input v-model="form.sl" placeholder="请输入总数量 -100不限数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="已售数量" prop="psl">
									<el-input v-model="form.psl" placeholder="请输入已售数量" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '充值促销'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					hyUserGoldPromotionId: "",
					regionPath: "",
					startTime: "",
					endTime: "",
					currency: "",
					pvalue: "",
					pprice: "",
					ptitle: "",
					ptitleImg: "",
					shortDesc: "",
					fullDesc: "",
					state: "",
					seq: "",
					sl: "",
					psl: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await this.$API.hygl.hyUserGoldPromotion.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.hyUserGoldPromotionId = data.hyUserGoldPromotionId;
				this.form.regionPath = data.regionPath;
				this.form.startTime = data.startTime;
				this.form.endTime = data.endTime;
				this.form.currency = data.currency;
				this.form.pvalue = data.pvalue;
				this.form.pprice = data.pprice;
				this.form.ptitle = data.ptitle;
				this.form.ptitleImg = data.ptitleImg;
				this.form.shortDesc = data.shortDesc;
				this.form.fullDesc = data.fullDesc;
				this.form.state = data.state;
				this.form.seq = data.seq;
				this.form.sl = data.sl;
				this.form.psl = data.psl;
			}
		}
	}
</script>
<style>
</style>
